<?php
//use backend\widgets\Menu;
use mdm\admin\components\MenuHelper;

?>
<aside class="main-sidebar">

    <section class="sidebar">
        <!-- Sidebar user panel -->
        <div class="user-panel">
            <div class="pull-left image">
                <img src="<?= Yii::$app->user->identity->avatar?>" class="img-circle" alt="User Image"/>
            </div>
            <div class="pull-left info">
                <p><?= Yii::$app->user->identity->username ?></p>
                <a href="javascript:void(0)"><?= Yii::$app->user->identity->position ?></a>
            </div>
        </div>
        <?=
        dmstr\widgets\Menu::widget(
            [
                'options' => ['class' => 'sidebar-menu'],
                'items'   => [
                    ['label' => '总览', 'url' => ['/'], 'icon' => 'fas fa-street-view'],
                    ['label' => '菜单', 'options' => ['class' => 'header']],
                ],
            ]
        ) ?>

        <?=
        \dmstr\widgets\Menu::widget([
            'options' => ['class' => 'sidebar-menu tree', 'data' => ['widget' => 'tree']],
            'items'   => MenuHelper::getAssignedMenu(Yii::$app->user->id, 0, function ($menu) {
                $data = @json_decode($menu['data'], true);
                return [
                    'label' => $menu['name'],
                    'url'   => [$menu['route']],
                    'icon'  => !isset($data['icon']) ? '' : $data['icon'],
                    'items' => $menu['children'],
                ];
            }),
        ]);
        ?>
    </section>
</aside>